﻿using System;
using System.Collections.Generic;

namespace FlashPay.Service.Impl
{
    using FlashPay.DAO.Bank;
    using FlashPay.DAO.Interface;
    using FlashPay.DAO.Order;
    using FlashPay.EF.Models;
    using FlashPay.Entity;
    using FlashPay.Entity.Enum;
    using FlashPay.Entity.Parameter;
    using FlashPay.Entity.Request.Order;
    using FlashPay.Entity.Response.Bank;
    using FlashPay.Entity.Response.Order;
    using FlashPay.Service.Interface;
    using System.Linq;
    using System.Text.RegularExpressions;

    /// <summary>
    /// 订单明细业务接口实现
    /// </summary>
    public class OrderRecordDetailServiceImpl: OrderRecordDetailService
    {
        #region 注入
        /// <summary>
        /// 订单数据接口
        /// </summary>
        private readonly OrderRecordDAO _orderRecordDao;

        /// <summary>
        /// 订单明细数据接口
        /// </summary>
        private readonly OrderRecordDetailDao _orderRecordDetailDao;

        /// <summary>
        /// 卡商数据接口
        /// </summary>
        private readonly CardMerchantDao _merchantDao;

        /// <summary>
        /// 日志权限数据接口
        /// </summary>
        private readonly LogDao _logDao;

        /// <summary>
        /// 银行数据接口
        /// </summary>
        private readonly BankInfoDAO _bankInfoDao;

        /// <summary>
        /// 日志模型
        /// </summary>
        private readonly LogRecord _logRecord;

        /// <summary>
        /// 注入
        /// </summary>
        /// <param name="orderRecordDao">订单数据接口</param>
        /// <param name="orderRecordDetailDao">订单明细数据接口</param>
        /// <param name="companyDao">公司数据接口</param>
        /// <param name="menuPermissionDao">菜单权限关联数据接口</param>
        /// <param name="authorizeDao">授权数据接口</param>
        public OrderRecordDetailServiceImpl(OrderRecordDAO orderRecordDao,OrderRecordDetailDao orderRecordDetailDao, CardMerchantDao merchantDao,LogDao logDao, BankInfoDAO bankInfoDao, LogRecord logRecordt)
        {
            _orderRecordDao = orderRecordDao;
            _orderRecordDetailDao = orderRecordDetailDao;
            _merchantDao = merchantDao;
            _logDao = logDao;
            _bankInfoDao = bankInfoDao;
            _logRecord = logRecordt;
        }
        #endregion

        /// <summary>
        /// 根据订单明细（包括订单部分信息）
        /// </summary>
        /// <param name="detailId">编号</param>
        /// <returns>SysRole</returns>
        public OrderRecordDetailResponse GetOrderRecordDetail(long detailId)
        {
            var orderRecordDetailResponse = new OrderRecordDetailResponse();

            var orderRecordDetail = _orderRecordDetailDao.GetOrderRecordDetail(detailId);
            if (orderRecordDetail != null)
            {
                orderRecordDetailResponse.DetailID = orderRecordDetail.DetailId;
                orderRecordDetailResponse.OrderNo = orderRecordDetail.OrderNo.ToString();
                orderRecordDetailResponse.BankCode = orderRecordDetail.BankCode;
                orderRecordDetailResponse.OrderQuantity = orderRecordDetail.OrderQuantity;
                orderRecordDetailResponse.ActualQuantity = orderRecordDetail.ActualQuantity;
                orderRecordDetailResponse.UnitPrice = orderRecordDetail.UnitPrice.ToString();
                orderRecordDetailResponse.ActualUnitPrice = orderRecordDetail.ActualUnitPrice.ToString();
                orderRecordDetailResponse.Remark = orderRecordDetail.Remark;

                #region 订单信息
                var orderRecord = _orderRecordDetailDao.GetOrderRecord(orderRecordDetail.OrderNo);
                if (orderRecord != null) {

                    orderRecordDetailResponse.CMID = orderRecord.Cmid;

                    orderRecordDetailResponse.DepositUid = orderRecord.DepositUid;
                    orderRecordDetailResponse.ReceiptUid = orderRecord.ReceiptUid;
                    orderRecordDetailResponse.PayUid = orderRecord.PayUid;

                    orderRecordDetailResponse.OrderCreateUID = orderRecord.CreateUid;
                }
                #endregion
            }

            return orderRecordDetailResponse;
        }

        /// <summary>
        /// 根据编号获取系统订单
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns>SysRole</returns>
        public JResult<OrderRecordResponse> GetOrderRecord(OrderRecordDetailQuery query)
        {
            var result = new JResult<OrderRecordResponse>()
            {
                Success = true
            };

            var orderRecordDetail = _orderRecordDetailDao.GetOrderRecord(query.OrderNo);

            var orderRecordResponse = new OrderRecordResponse();
            if (orderRecordDetail != null)
            {
                orderRecordResponse.OrderNo = orderRecordDetail.OrderNo.ToString();
                orderRecordResponse.OrderDate = orderRecordDetail.OrderDate;
                orderRecordResponse.DepositUID = orderRecordDetail.DepositUid;
                orderRecordResponse.ReceiptUID = orderRecordDetail.ReceiptUid;
                orderRecordResponse.PayUID = orderRecordDetail.PayUid;
                orderRecordResponse.IsCurrentUser = query.UserId == orderRecordDetail.CreateUid;
                orderRecordResponse.IsAuth = false;
                if (query.userPermission.Contains("Order0017"))
                {
                    orderRecordResponse.IsAuth = true;
                }
                result.Data = orderRecordResponse;
            }

            return result;
        }

        #region 根据编号获取订单明细
        /// <summary>
        /// 根据编号获取订单明细
        /// </summary>
        /// <param name="id">编号</param>
        /// <returns>SysRole</returns>
        public OrderRecordDetailResponse Get(long orderNo, int detailId)
        {
            var orderRecordDetailResponse = new OrderRecordDetailResponse();
            if (detailId > 0)
            {
                orderRecordDetailResponse = _orderRecordDetailDao.Get(detailId);
            }
            else {
                var orderRecord = _orderRecordDetailDao.GetOrderRecord(orderNo);
                if (orderRecord != null) {
                    orderRecordDetailResponse.DepositUid = orderRecord.DepositUid;
                    orderRecordDetailResponse.ReceiptUid = orderRecord.ReceiptUid;
                    orderRecordDetailResponse.PayUid = orderRecord.PayUid;
                }
            }

            #region 银行
            var bankinfoList = _bankInfoDao.GetBankInfoList();

            var bankinfoResponse = new List<BankInfoResponse>();

            if (bankinfoList != null)
            {
                foreach (var item in bankinfoList)
                {
                    bankinfoResponse.Add(new BankInfoResponse()
                    {
                        BankCode = item.BankCode,
                        BankName = item.BankName
                    });
                }
            }
            orderRecordDetailResponse.BankInfoResponses = bankinfoResponse;
            #endregion

            return orderRecordDetailResponse;
        }


        #endregion

        /// <summary>
        /// 权限验证
        /// </summary>
        /// <param name="userPermission"></param>
        /// <param name="userId"></param>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public bool IsVerify(List<String> userPermission,int userId,long orderDetailNo) {

            var status = false;

            var orderRecordDetail = _orderRecordDetailDao.GetOrderRecord(orderDetailNo);

            if (userPermission.Contains("OrderDetail0005") || userPermission.Contains("Order0017"))
            {
                if (!userPermission.Contains("Order0017")){
                    if (userId == orderRecordDetail.CreateUid){
                        status = true;
                    }
                }else{
                    status = true;
                }
            }
            else {
                if (userId == orderRecordDetail.CreateUid){
                    status = true;
                }
            }
            return status;
        }

        #region 新增、编辑
        /// <summary>
        /// 新增、编辑
        /// </summary>
        /// <param name="request"></param>
        public JResult EditOrAdd(OrderRecordDetailEditOrAddRequest request)
        {
            var result = new JResult()
            {
                Success = false
            };

            try
            {
                var model = new OrderRecordDetail();

                #region 数据验证

                if (request.Type.Equals(1))
                {
                    #region 常规修改
                    if (request.DetailId > 0)
                    {
                        model = _orderRecordDetailDao.GetOrderRecordDetail(request.DetailId);

                        var orderRecord = _orderRecordDetailDao.GetOrderRecord(request.OrderNo);
                        if (!request.userPermission.Contains("Order0017"))
                        {
                            if (orderRecord.CreateUid != request.CreateUid)
                            {
                                throw new Exception("操作失败，订单不属于该用户");
                            }
                        }
                        //银行名称
                        if (string.IsNullOrEmpty(request.BankCode))
                        {
                            throw new Exception("请选择银行名称！");
                        }

                        //下单数量
                        if (request.OrderQuantity <= 0)
                        {
                            throw new Exception("请填写下单数量，只能为正整数");
                        }
                        var orderQuantityReg = new Regex(@"^([1-9][0-9]*){1,3}$");
                        if (!orderQuantityReg.IsMatch(request.OrderQuantity.ToString()))
                        {
                            throw new Exception("请填写下单数量，只能为正整数");
                        }

                        //单价
                        if (IsVerify(request.userPermission, request.CreateUid, model.OrderNo)) {
                            if (request.UnitPrice <= 0)
                            {
                                throw new Exception("请填写下单数量，最大保留两位小数");
                            }

                            var unitPriceReg = new Regex(@"^([1-9][0-9]*)+(.[0-9]{1,2})?$");
                            if (!unitPriceReg.IsMatch(request.UnitPrice.ToString()))
                            {
                                throw new Exception("请填写下单数量，最大保留两位小数");
                            }
                        }

                        //实际数量
                        if (request.ActualQuantity <= 0)
                        {
                            throw new Exception("请填写下实际数量，只能为正整数");
                        }
                        var actualQuantityReg = new Regex(@"^([1-9][0-9]*){1,3}$");
                        if (!actualQuantityReg.IsMatch(request.ActualQuantity.ToString()))
                        {
                            throw new Exception("请填写下实际数量，只能为正整数");
                        }

                        //实际单价
                        if (IsVerify(request.userPermission, request.CreateUid, model.OrderNo))
                        {
                            if (request.ActualUnitPrice <= 0)
                            {
                                throw new Exception("请填写实际单价，最大保留两位小数");
                            }
                            var actualUnitPriceReg = new Regex(@"^([1-9][0-9]*)+(.[0-9]{1,2})?$");
                            if (!actualUnitPriceReg.IsMatch(request.ActualUnitPrice.ToString()))
                            {
                                throw new Exception("请填写实际单价，最大保留两位小数");
                            }
                        }

                        //备注
                        if (!string.IsNullOrEmpty(request.Remark))
                        {
                            //var reg = new Regex(@"^[\u4E00-\u9FA5A-Za-z0-9_]+$");
                            //if (!reg.IsMatch(request.Remark))
                            //{
                            //    throw new Exception("备注由中英文、数字包括下划线");
                            //}
                        }

                        
                        model.BankCode = request.BankCode;
                        model.OrderQuantity = request.OrderQuantity;
                        model.ActualQuantity = request.ActualQuantity;
                        if (IsVerify(request.userPermission, request.CreateUid, model.OrderNo))
                        {
                            model.UnitPrice = request.UnitPrice;
                            model.ActualUnitPrice = request.ActualUnitPrice;
                        }
                        model.Remark = request.Remark;

                        //订单验证
                        if (orderRecord == null)
                        {
                            throw new Exception("订单失效");
                        }

                        if (orderRecord.ReceiptUid > 0)
                        {
                            throw new Exception("收货人已审核，不能修改！");
                        }
                    }
                    else
                    {
                        //订单编号
                        if (string.IsNullOrEmpty(request.OrderNo.ToString()))
                        {
                            throw new Exception("参数错误！");
                        }
                        //银行名称
                        if (string.IsNullOrEmpty(request.BankCode))
                        {
                            throw new Exception("请选择银行名称！");
                        }

                        //下单数量
                        if (request.OrderQuantity <= 0)
                        {
                            throw new Exception("请填写下单数量，只能为正整数");
                        }
                        var orderQuantityReg = new Regex(@"^([1-9][0-9]*){1,3}$");
                        if (!orderQuantityReg.IsMatch(request.OrderQuantity.ToString()))
                        {
                            throw new Exception("请填写下单数量，只能为正整数");
                        }

                        //单价
                        if (request.UnitPrice <= 0)
                        {
                            throw new Exception("请填写下单数量，最大保留两位小数");
                        }

                        var unitPriceReg = new Regex(@"^([1-9][0-9]*)+(.[0-9]{1,2})?$");
                        if (!unitPriceReg.IsMatch(request.UnitPrice.ToString()))
                        {
                            throw new Exception("请填写下单数量，最大保留两位小数");
                        }

                        //实际数量
                        if (request.ActualQuantity <= 0)
                        {
                            throw new Exception("请填写下实际数量，只能为正整数");
                        }
                        var actualQuantityReg = new Regex(@"^([1-9][0-9]*){1,3}$");
                        if (!actualQuantityReg.IsMatch(request.ActualQuantity.ToString()))
                        {
                            throw new Exception("请填写下实际数量，只能为正整数");
                        }

                        //实际单价
                        if (request.ActualUnitPrice <= 0)
                        {
                            throw new Exception("请填写实际单价，最大保留两位小数");
                        }
                        var actualUnitPriceReg = new Regex(@"^([1-9][0-9]*)+(.[0-9]{1,2})?$");
                        if (!actualUnitPriceReg.IsMatch(request.ActualUnitPrice.ToString()))
                        {
                            throw new Exception("请填写实际单价，最大保留两位小数");
                        }

                        //备注
                        if (!string.IsNullOrEmpty(request.Remark))
                        {
                            //var reg = new Regex(@"^[\u4E00-\u9FA5A-Za-z0-9_]+$");
                            //if (!reg.IsMatch(request.Remark))
                            //{
                            //    throw new Exception("备注由中英文、数字包括下划线");
                            //}
                        }

                        model.OrderNo = request.OrderNo;
                        model.BankCode = request.BankCode;
                        model.OrderQuantity = request.OrderQuantity;
                        model.UnitPrice = request.UnitPrice;
                        model.ActualQuantity = request.ActualQuantity;
                        model.ActualUnitPrice = request.ActualUnitPrice;
                        model.Remark = request.Remark;
                        model.CreateUid = request.CreateUid;
                        model.CreateDate = DateTime.Now;

                        //订单验证
                        var orderRecord = _orderRecordDetailDao.GetOrderRecord(model.OrderNo);
                        if (orderRecord == null)
                        {
                            throw new Exception("订单失效");
                        }

                        if (orderRecord.ReceiptUid > 0)
                        {
                            throw new Exception("收货人已审核，不能新增！");
                        }
                    }
                    #endregion
                }
                else
                {
                    #region 补单修改
                    if (request.DetailId > 0)
                    {
                        model = _orderRecordDetailDao.GetOrderRecordDetail(request.DetailId);

                        var orderRecord = _orderRecordDetailDao.GetOrderRecord(request.OrderNo);
                        if (!request.userPermission.Contains("Order0017"))
                        {
                            if (orderRecord.CreateUid != request.CreateUid)
                            {
                                throw new Exception("操作失败，订单不属于该用户");
                            }
                        }
                        //实际数量
                        if (request.ActualQuantity <= 0)
                        {
                            throw new Exception("请填写下实际数量，只能为正整数");
                        }
                        var actualQuantityReg = new Regex(@"^([1-9][0-9]*){1,3}$");
                        if (!actualQuantityReg.IsMatch(request.ActualQuantity.ToString()))
                        {
                            throw new Exception("请填写下实际数量，只能为正整数");
                        }
                        //实际单价
                        if (IsVerify(request.userPermission,request.CreateUid,model.OrderNo))
                        {
                            if (request.ActualUnitPrice <= 0)
                            {
                                throw new Exception("请填写实际单价，最大保留两位小数");
                            }
                            var actualUnitPriceReg = new Regex(@"^([1-9][0-9]*)+(.[0-9]{1,2})?$");
                            if (!actualUnitPriceReg.IsMatch(request.ActualUnitPrice.ToString()))
                            {
                                throw new Exception("请填写实际单价，最大保留两位小数");
                            }
                        }

                        //备注
                        if (!string.IsNullOrEmpty(request.Remark))
                        {
                            //var reg = new Regex(@"^[\u4E00-\u9FA5A-Za-z0-9_]+$");
                            //if (!reg.IsMatch(request.Remark))
                            //{
                            //    throw new Exception("备注由中英文、数字包括下划线");
                            //}
                        }
                        model.ActualQuantity = request.ActualQuantity;
                        if (IsVerify(request.userPermission, request.CreateUid, model.OrderNo))
                        {
                            model.ActualUnitPrice = request.ActualUnitPrice;
                        }
                        model.Remark = request.Remark;

                        //订单验证
                        if (orderRecord == null) {
                            throw new Exception("订单失效");
                        }

                        if (orderRecord.ReceiptUid > 0) {
                            throw new Exception("收货人已审核，不能修改！");
                        }
                    }
                    else
                    {
                        //订单编号
                        if (string.IsNullOrEmpty(request.OrderNo.ToString()))
                        {
                            throw new Exception("参数错误！");
                        }
                        //银行名称
                        if (string.IsNullOrEmpty(request.BankCode))
                        {
                            throw new Exception("请选择银行名称！");
                        }

                        //实际数量
                        if (request.ActualQuantity <= 0)
                        {
                            throw new Exception("请填写下实际数量，只能为正整数");
                        }
                        var actualQuantityReg = new Regex(@"^([1-9][0-9]*){1,3}$");
                        if (!actualQuantityReg.IsMatch(request.ActualQuantity.ToString()))
                        {
                            throw new Exception("请填写下实际数量，只能为正整数");
                        }

                        //实际单价
                        if (request.ActualUnitPrice <= 0)
                        {
                            throw new Exception("请填写实际单价，最大保留两位小数");
                        }
                        var actualUnitPriceReg = new Regex(@"^([1-9][0-9]*)+(.[0-9]{1,2})?$");
                        if (!actualUnitPriceReg.IsMatch(request.ActualUnitPrice.ToString()))
                        {
                            throw new Exception("请填写实际单价，最大保留两位小数");
                        }

                        //备注
                        if (!string.IsNullOrEmpty(request.Remark))
                        {
                            //var reg = new Regex(@"^[\u4E00-\u9FA5A-Za-z0-9_]+$");
                            //if (!reg.IsMatch(request.Remark))
                            //{
                            //    throw new Exception("备注由中英文、数字包括下划线");
                            //}
                        }

                        model.OrderNo = request.OrderNo;
                        model.BankCode = request.BankCode;
                        model.OrderQuantity = 0;
                        model.UnitPrice = 0;
                        model.ActualQuantity = request.ActualQuantity;
                        model.ActualUnitPrice = request.ActualUnitPrice;
                        model.Remark = request.Remark;
                        model.CreateUid = request.CreateUid;
                        model.CreateDate = DateTime.Now;

                        //订单验证
                        var orderRecord = _orderRecordDetailDao.GetOrderRecord(model.OrderNo);
                        if (orderRecord == null)
                        {
                            throw new Exception("订单失效");
                        }

                        if (orderRecord.ReceiptUid > 0)
                        {
                            throw new Exception("收货人已审核，不能新增！");
                        }
                    }
                    #endregion
                }

                #endregion

                if (request.DetailId > 0)
                {
                    //权限验证
                    var orderRecordDetailList = _orderRecordDetailDao.GetList(new OrderRecordDetailQuery() { NoEqualDetailId = request.DetailId,OrderNo=request.OrderNo,BankCode=request.BankCode });
                    if (orderRecordDetailList != null && orderRecordDetailList.Any()) {
                        throw new Exception("同一个订单不添加相同的银行名称！");
                    }
                    var updateResult = _orderRecordDetailDao.Update(model);
                    if (updateResult)
                    {
                        //日志
                        _logRecord.LogType = LogRecordLogType.CardOrder_Child_Add.GetHashCode();
                        _logRecord.LogLevel = (sbyte)LogLevel.Success.GetHashCode();
                        _logRecord.CreateDate = DateTime.Now;
                        _logRecord.LogRemark = "编辑成功";
                        _logDao.Insert(_logRecord);

                        result.Success = true;
                        result.SuccessMessage = "编辑订单明细成功";
                    }
                    else
                    {
                        //日志
                        _logRecord.LogType = LogRecordLogType.CardOrder_Child_Add.GetHashCode();
                        _logRecord.LogLevel = (sbyte)LogLevel.Failure.GetHashCode();
                        _logRecord.CreateDate = DateTime.Now;
                        _logRecord.LogRemark = "编辑失败";
                        _logDao.Insert(_logRecord);

                        result.Success = false;
                        result.SuccessMessage = "编辑订单明细失败";
                    }
                }
                else
                {
                    var orderRecordDetailList = _orderRecordDetailDao.GetList(new OrderRecordDetailQuery() { OrderNo = request.OrderNo, BankCode = request.BankCode });
                    if (orderRecordDetailList != null && orderRecordDetailList.Any())
                    {
                        throw new Exception("同一个订单不添加相同的银行名称！");
                    }

                    var addResult = _orderRecordDetailDao.Add(model);
                    if (addResult.Success)
                    {
                        //日志
                        _logRecord.LogType = LogRecordLogType.CardOrder_Child_Update.GetHashCode();
                        _logRecord.LogLevel = (sbyte)LogLevel.Success.GetHashCode();
                        _logRecord.CreateDate = DateTime.Now;
                        _logRecord.LogRemark = "新增成功";
                        _logDao.Insert(_logRecord);

                        result.Success = true;
                        result.SuccessMessage = "新增订单明细成功";
                    }
                    else {
                        //日志
                        _logRecord.LogType = LogRecordLogType.CardOrder_Child_Update.GetHashCode();
                        _logRecord.LogLevel = (sbyte)LogLevel.Failure.GetHashCode();
                        _logRecord.CreateDate = DateTime.Now;
                        _logRecord.LogRemark = "新增失败";
                        _logDao.Insert(_logRecord);

                        result.Success = false;
                        result.SuccessMessage = "新增订单明细失败";
                    }
                }
            }
            catch (Exception ex) {
                result.ErrorMessage = ex.Message;
            }

            return result;
        }
        #endregion

        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="detailId">系统编号</param>
        /// <returns></returns>
        public JResult DeleteByDetailId(List<String> userPermission,int userId,int detailId)
        {
            var response = new JResult()
            {
                Success = false
            };

            try
            {
                var orderRecordDetail = GetOrderRecordDetail(detailId);
                if (orderRecordDetail == null)
                {
                    throw new Exception("订单明细不存在");
                }

                if (!userPermission.Contains("Order0017"))
                {
                    if (userId != orderRecordDetail.OrderCreateUID)
                    {
                        throw new Exception("删除失败！此订单明细不属于当前用户");
                    }
                }
                
                var orderRecord = _orderRecordDetailDao.GetOrderRecord(long.Parse(orderRecordDetail.OrderNo));
                if (orderRecordDetail == null)
                {
                    throw new Exception("所属订单不存在");
                }

                if (orderRecord.ReceiptUid > 0 || orderRecord.PayUid > 0) {
                    throw new Exception("订单状态已发生改变，不能删除");
                }

                var status = _orderRecordDetailDao.DeleteByDetailId(detailId);
                if (status)
                {
                    response.Success = true;
                    response.SuccessMessage = "删除订单明细成功";
                }
                else {
                    response.Success = false;
                    response.SuccessMessage = "删除订单明细失败";
                }
            }
            catch (Exception ex) {
                response.ErrorMessage = ex.Message;
            }

            return response;
        }
        #endregion

        #region 分页查询
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="query">查询条件</param>
        /// <returns>PagedList<Permission></returns>
        public PagedList<OrderRecordDetailResponse> GetPager(OrderRecordDetailQuery query)
        {
            var pager = _orderRecordDetailDao.GetPager(query);

            var orderRecordDetailResponses = new List<OrderRecordDetailResponse>();

            if (pager.TData != null && pager.TData.Any()) {

                foreach (var item in pager.TData) {

                    var orderRecordDetailResponse = new OrderRecordDetailResponse()
                    {
                        DetailID = item.DetailID,
                        OrderNo = item.OrderNo,
                        BankCode = item.BankCode,

                        OrderQuantity = item.OrderQuantity,
                        ActualQuantity = item.ActualQuantity,

                        //UnitPrice = item.UnitPrice,
                        //ActualUnitPrice = item.ActualUnitPrice,

                        Remark = item.Remark,
                        CreateUID = item.CreateUID,
                        CreateDate = item.CreateDate,

                        BankName = item.BankName,

                        DepositUid = item.DepositUid,
                        ReceiptUid = item.ReceiptUid,
                        PayUid = item.PayUid,
                        IsCurrentUser = query.UserId == item.OrderCreateUID,
                        IsAuth = false
                    };
                    if (IsVerify(query.userPermission, query.UserId,long.Parse(item.OrderNo)))
                    {
                        orderRecordDetailResponse.UnitPrice = item.UnitPrice;
                        orderRecordDetailResponse.ActualUnitPrice = item.ActualUnitPrice;
                    }
                    else {
                        orderRecordDetailResponse.UnitPrice = "**.**";
                        orderRecordDetailResponse.ActualUnitPrice = "**.**";
                    }

                    if (query.userPermission.Contains("Order0017"))
                    {
                        orderRecordDetailResponse.IsAuth = true;
                    }
                    orderRecordDetailResponses.Add(orderRecordDetailResponse);
                }
            }

            return new PagedList<OrderRecordDetailResponse>() {
                TotalCount = pager.TotalCount,
                TData = orderRecordDetailResponses,
                Success = pager.Success,
            };
        }
        #endregion
    }
}
